package com.github.thinwonton.springboot.showcase.mybatis.service;

import com.github.thinwonton.springboot.showcase.mybatis.constant.OrderConstants;
import com.github.thinwonton.springboot.showcase.mybatis.dao.OrdersDao;
import com.github.thinwonton.springboot.showcase.mybatis.domain.Orders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class OrdersService {
    @Autowired
    private OrdersDao ordersDao;

    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public void updateStatus(Long id) {
        Orders orders = ordersDao.selectByPrimaryKey(id);
        orders.setStatus(OrderConstants.ORDER_STATUS_PAID);
        ordersDao.updateByPrimaryKeySelective(orders);
    }
}
